package com.xtoad.ecms.baseinfo.model;

import com.xtoad.ecms.common.web.base.BaseModel;
import org.hibernate.annotations.Table;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import java.util.List;


/**
 * 角色实体类
 *
 * @author xtoad
 * @date 2020/05/29
 */
@Entity
@Table(appliesTo = "role", comment = "角色表")
public class Role extends BaseModel {

    /**
     * 角色编码
     */
    @Column(nullable = false, unique = true, columnDefinition = "varchar(25) comment '角色编码'")
    private String code;

    /**
     * 角色名称
     */
    @Column(nullable = false, unique = true, columnDefinition = "varchar(50) comment '角色名称'")
    private String name;

    /**
     * 用户列表
     */
    @ManyToMany(fetch = FetchType.LAZY)
    private List<User> users;

    /**
     * 构造方法
     *
     * @param code 角色编码
     * @param name 角色名称
     */
    public Role(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 默认构造方法
     */
    public Role() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Role{");
        sb.append("code='").append(code).append('\'');
        sb.append(", name='").append(name).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
